// pages/map/map.js

var QQMapWX = require('../libs/qqmap-wx-jssdk.js');
Page({

  /**
   * 页面的初始数据
   */

     data: {
        scale:'13',
        //
        longitude: '',
        latitude: '',
        markers: [
           {
           iconPath: "../../images/ding.png",
           id: 0,
           latitude: 40.002607,
           longitude: 116.487847,
           width: 35,
           height: 45
        },
           {
              iconPath: "../../images/ding.png",
              id: 1,
              longitude: '116.496507',
              latitude: '40.006103',
              width: 35,
              height: 45
           }
        ],

        polyline: [
           {
           points: [ 
              {
              longitude: '116.487847',
              latitude: '40.002607'
           }, 
           {
              longitude: '116.496507',
              latitude: '40.006103'
           }
           ],
           color: "#FF0000DD",
           width: 3,
           dottedLine: true
        }
        
        
        
        ],
     
        controls: [
           {
              id: 1,
              iconPath: '../../images/bai.png',
              position: {
                 left: 325,
                 top: 240,
                 width: 30,
                 height: 100
              },

           },

           {
              id: 2,
              iconPath: '../../images/jia.png',
              position: {
                 left: 330,
                 top: 250,
                 width: 20,
                 height: 20
              },
              clickable: true
           },
           {
              id: 3,
              iconPath: '../../images/jian.png',
              position: {
                 left: 330,
                 top: 300,
                 width: 20,
                 height: 15
              },
              clickable: true
           },


        ]

  },
     //点击缩放按钮动态请求数据
     controltap(e) {
        console.log(e)
        var that = this;
        console.log("scale===" + this.data.scale)
        if (e.controlId == 3) {
           that.setData({
              scale: --this.data.scale
           })
        }

        if (e.controlId == 2) {
           that.setData({
              scale: ++this.data.scale
           })
        }   },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
   //   qqmapsdk = new QQMapWX({
   //      key: '3F4BZ-6RBR6-Q3HSQ-ML5JH-KF22H-YTBRQ'
   //   });
     var that = this;
      var polyline = that.data.polyline
      var lat = polyline.latitude;
       var log = polyline.longitude;
    
       console.log(polyline[0].points)
     wx.getLocation({
        type: 'gcj02',
        success: function (res) {
           console.log(res)
           that.setData({
              longitude: res.longitude,
              latitude: res.latitude,
              'polyline[0].points[0].latitude': res.latitude,
              'polyline[0].points[0].longitude': res.longitude,
           });
           console.log(res.longitude + " " + res.latitude);
  },
     })




      },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})